package com.bzkj.web.controller.yxl;

import com.bzkj.basicinfo.service.yxl.YxlReportService;
import com.bzkj.common.annotation.LogC;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author：swj
 * @Desc
 * @Date：2025/8/13 10:54
 */
@RestController
@RequestMapping("/yxl/billReport")
public class YxlBillsReportController extends BaseController {
    @Autowired
    private YxlReportService yxlReportService;

    /**
     * 商品TOP10
     *
     * @param type
     * @return
     */
    @GetMapping("/top10")
    public AjaxResult queryTop10(@RequestParam(value = "type") String type) {
        return AjaxResult.success(yxlReportService.queryTop10(type));
    }

    /**
     * 低库存预警
     *
     * @return
     */
    @GetMapping("/lowInventoryWarning")
    public AjaxResult lowInventory(Integer pageNum, Integer pageSize) {
        return AjaxResult.success(yxlReportService.lowInventory(pageNum, pageSize));
    }

    /**
     * 效期预警
     *
     * @return
     */
    @GetMapping("/expWarning")
    public AjaxResult expWarning(Integer pageNum, Integer pageSize) {
        return AjaxResult.success(yxlReportService.expWarning(pageNum, pageSize));
    }

    /**
     * 实时概况
     *
     * @return
     */
    @GetMapping("/realTime")
    public AjaxResult realTime() {
        return yxlReportService.realTime();
    }

    /**
     * 库存出入库明细统计
     *
     * @param type
     * @param stoId
     * @param startDate
     * @param endDate
     * @param drugCD
     * @param drugBatchNo
     * @param drugName
     * @param userName
     * @param drugJwh
     * @return
     */
    @GetMapping("/queryWarehouseOutInDetail")
    public AjaxResult queryWarehouseOutInDetail(@RequestParam(required = false, defaultValue = "") Integer type,
                                                @RequestParam(required = false, defaultValue = "") String stoId,
                                                @RequestParam(required = false, defaultValue = "") String startDate,
                                                @RequestParam(required = false, defaultValue = "") String endDate,
                                                @RequestParam(required = false, defaultValue = "") String drugCD,
                                                @RequestParam(required = false, defaultValue = "") String drugBatchNo,
                                                @RequestParam(required = false, defaultValue = "") String drugName,
                                                @RequestParam(required = false, defaultValue = "") String userName,
                                                @RequestParam(required = false, defaultValue = "") String drugJwh,
                                                Integer pageNum, Integer pageSize
    ) {
        return yxlReportService.queryWarehouseOutInDetail(type, stoId, startDate, endDate, drugCD, drugBatchNo,
                drugName, userName, drugJwh, pageNum, pageSize);
    }

    @PostMapping("/exportWarehouseOutInDetail")
    @LogC(title = "库存出入库明细", businessType = BusinessType.EXPORT)
    public AjaxResult exportWarehouseOutInDetail(@RequestParam(required = false, defaultValue = "") Integer type,
                                                 @RequestParam(required = false, defaultValue = "") String stoId,
                                                 @RequestParam(required = false, defaultValue = "") String startDate,
                                                 @RequestParam(required = false, defaultValue = "") String endDate,
                                                 @RequestParam(required = false, defaultValue = "") String drugCD,
                                                 @RequestParam(required = false, defaultValue = "") String drugBatchNo,
                                                 @RequestParam(required = false, defaultValue = "") String drugName,
                                                 @RequestParam(required = false, defaultValue = "") String userName,
                                                 @RequestParam(required = false, defaultValue = "") String drugJwh,
                                                 @RequestParam String selectedColumns,
                                                 HttpServletResponse response) {
        return yxlReportService.exportWarehouseOutInDetail(type, stoId, startDate, endDate, drugCD, drugBatchNo,
                drugName, userName, drugJwh, selectedColumns, response);
    }

    /**
     * 入库单据
     *
     * @return
     */
    @GetMapping("/queryInBillsList")
    public AjaxResult queryInBillsList(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                       String userName, String isQr, Integer pageNum, Integer pageSize) {
        return yxlReportService.queryInBillsList(billsId, stoId, startDate, endDate, billsCd, userName, isQr, pageNum, pageSize);
    }

    /**
     * 导出入库单据
     *
     * @return
     */
    @PostMapping("/exportInBillsList")
    @LogC(title = "导出入库单据", businessType = BusinessType.EXPORT)
    public AjaxResult exportInBillsList(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                        String userName, String isQr, HttpServletResponse response) {
        return yxlReportService.exportInBillsList(billsId, stoId, startDate, endDate, billsCd, userName, isQr, response);
    }

    /**
     * 出库单据
     *
     * @return
     */
    @GetMapping("/queryOutBillsList")
    public AjaxResult queryOutBillsList(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                        String userName, String isQr, Integer pageNum, Integer pageSize) {
        return yxlReportService.queryOutBillsList(billsId, stoId, startDate, endDate, billsCd, userName, isQr, pageNum, pageSize);
    }

    /**
     * 导出出库单据
     *
     * @return
     */
    @PostMapping("/exportOutBillsList")
    @LogC(title = "导出出库单据", businessType = BusinessType.EXPORT)
    public AjaxResult exportOutBillsList(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                         String userName, String isQr, HttpServletResponse response) {
        return yxlReportService.exportOutBillsList(billsId, stoId, startDate, endDate, billsCd, userName, isQr, response);
    }

    @GetMapping("/queryWarehouseMoveList")
    public TableDataInfo queryWarehouseMoveList(String userName, String spmch, String batchCode,String startDate,String endDate) {
        startPage();
        return getDataTable(yxlReportService.queryWarehouseMoveList(userName, spmch, batchCode,startDate,endDate));
    }

    @GetMapping("/queryInChartInfo")
    public AjaxResult queryInChartInfo(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                       String userName, String isQr) {
        return yxlReportService.queryInChartInfo();
    }

    @GetMapping("/queryOutChartInfo")
    public AjaxResult queryOutChartInfo(String billsId, String stoId, String startDate, String endDate, String billsCd,
                                        String userName, String isQr) {
        return yxlReportService.queryOutChartInfo();
    }

    @GetMapping("/queryCustomer")
    public AjaxResult queryCustomer(String type) {
        return yxlReportService.queryCustomer(type);
    }

    @GetMapping("/queryCustomerMonthAndYear")
    public AjaxResult queryCustomerMonthAndYear(@RequestParam(required = false,defaultValue = "") String dateRange) {
        return yxlReportService.queryCustomerMonthAndYear(dateRange);
    }

    @GetMapping("/queryBarCode")
    public AjaxResult queryBarCode(String barCode,String orderId,Integer pageNum,Integer pageSize) {
        return yxlReportService.queryBarCode(barCode,orderId,pageNum,pageSize);
    }

    @GetMapping("/queryBarCodeByParentCode")
    public AjaxResult queryBarCodeByParentCode( String barCode) {
        return yxlReportService.queryBarCodeByParentCode(barCode);
    }

    @GetMapping("/queryUnsalableDrug")
    public AjaxResult queryUnsalableDrug(String stoId, String spbh, String startDate, String endDate,Integer pageNum,Integer pageSize) {
        return yxlReportService.queryUnsalableDrug(stoId, spbh, startDate, endDate,pageNum,pageSize);
    }

    @GetMapping("/querySalableDrug")
    public AjaxResult querySalableDrug(String stoId,  String spbh, String startDate,String endDate,Integer pageNum,Integer pageSize) {
        return yxlReportService.querySalableDrug(stoId,  spbh, startDate, endDate,pageNum,pageSize);
    }
    @ApiOperation("导出畅销品")
    @LogC(title = "导出畅销品", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSalableDrug")
    public AjaxResult exportSalableDrug(String stoId,  String spbh, String startDate,String endDate,HttpServletResponse response) {
        return yxlReportService.exportSalableDrug(stoId, spbh, startDate, endDate,response);
    }

    @ApiOperation("导出滞销品")
    @LogC(title = "导出滞销品", businessType = BusinessType.EXPORT)
    @PostMapping("/exportUnSalableDrug")
    public AjaxResult exportUnSalableDrug(String stoId,  String spbh, String startDate,String endDate,HttpServletResponse response) {
        return yxlReportService.exportUnSalableDrug(stoId, spbh, startDate, endDate,response);
    }

    @GetMapping("/countUnitNum")
    public AjaxResult countUnitNum(@RequestParam(required = false,defaultValue = "") String stoId,
                                   @RequestParam(required = false,defaultValue = "") String type) {
        return yxlReportService.countUnitNum(stoId,type);
    }

    @GetMapping("/queryAreaByStoId")
    public AjaxResult queryAreaByStoId(@RequestParam(required = false,defaultValue = "") String stoId) {
        return yxlReportService.queryAreaByStoId(stoId);
    }

    @GetMapping("/queryUnitByAreaId")
    public AjaxResult queryUnitByAreaId(@RequestParam(required = false,defaultValue = "") String stoId,
                                   @RequestParam(required = false,defaultValue = "") String stoAreaId) {
        return yxlReportService.queryUnitByAreaId(stoId,stoAreaId);
    }

    @GetMapping("/querySkuByUnitCode")
    public AjaxResult querySkuByUnitCode(@RequestParam(required = false,defaultValue = "") String unitCode) {
        return yxlReportService.querySkuByUnitCode(unitCode);
    }

    @GetMapping("/queryUnitNum")
    public AjaxResult queryUnitNum() {
        return yxlReportService.queryUnitNum();
    }


}
